package StudyCode.summary.mycollection;

import java.util.ArrayList;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class SearchAnElementOfArrayList {
	public static void main(String[] args) {
		ArrayList arrayList = new ArrayList();
		arrayList.add("1");
		arrayList.add("2");
		arrayList.add("3");
		arrayList.add("4");
		arrayList.add("5");
		arrayList.add("1");
		arrayList.add("2");

		boolean blnFound = arrayList.contains("2");
		System.out.println("是否包含 2 ? " + blnFound);

		int index = arrayList.indexOf("4");
		if (index == -1)
			System.out.println("ArrayList 不否包含 4");
		else
			System.out.println("ArrayList 包含4，索引是 :" + index);

		int lastIndex = arrayList.lastIndexOf("1");
		if (lastIndex == -1)
			System.out.println("ArrayList 不否包含 1");
		else
			System.out.println("ArrayList中最后出现1的索引是 :" + lastIndex);
	}
}
